package com.mooc.lib_video.adapter

import android.util.Log
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.button.MaterialButton
import com.mooc.ijk.widget.IJKView
import com.mooc.lib_network.imgload.ImageLoad
import com.mooc.lib_video.R
import com.mooc.lib_common.model.FeedEntity

class HomeVideoAdapter : BaseMultiItemQuickAdapter<FeedEntity,BaseViewHolder>() {

    init {
        addChildClickViewIds(R.id.feed_tag_btn)
        addItemType(1, R.layout.layout_feed_type_image)
        addItemType(2,R.layout.layout_feed_type_video)
    }

    override fun convert(holder: BaseViewHolder, item: FeedEntity) {
        //公共属性配置
        var avatar = holder.getView<ImageView>(R.id.avatar)
        ImageLoad.loadMatch(item.author!!.avatar,avatar)
        holder.setText(R.id.author_name,item.author!!.name)
        holder.setText(R.id.create_time, TimeUtils.millis2String(item.createTime))
        holder.setText(R.id.feed_tag_btn,item.feeds_text)
        val like : MaterialButton = holder.getView(R.id.like)
        val diss : MaterialButton = holder.getView(R.id.diss)
        val comment : MaterialButton = holder.getView(R.id.comment)
        val share : MaterialButton = holder.getView(R.id.share)
        like.text = ""+item.ugc!!.likeCount
        diss.text = ""+item.ugc!!.likeCount
        comment.text = ""+item.ugc!!.commentCount
        share.text = ""+item.ugc!!.shareCount
//        val manager = LinearLayoutManager(context)
//        manager.orientation = LinearLayoutManager.VERTICAL
//        val list_img_commend_rv : RecyclerView = holder.getView(R.id.list_img_commend_rv)
//        list_img_commend_rv.layoutManager = manager
//        val commentsAdapter = HomeVideoCommentAdapter()
//        list_img_commend_rv.adapter = commentsAdapter
//        commentsAdapter.setNewInstance(item.comments)
        if (item.itemType == 1){
            var img = holder.getView<ImageView>(R.id.feed_image)
            var imgPath : String ?= null
            if (item.cover == null)
                imgPath = ""
            else
                imgPath = item.cover!!
            ImageLoad.loadMatch(imgPath!!,img)
        }else  if (item.itemType == 2){
            var ijk = holder.getView<IJKView>(R.id.list_player_view)
            ijk.setConverPath(item.cover!!)
        }
    }
}